<?php
define('SCR','type');
require_once('global.php');
require_once(R_P . 'require/init.php');

$typeid = isset($_GET['typeid']) ? intval($_GET['typeid']) : null;
$page = intval($_GET['page']);
$order = $_GET['order'];
if ($_GET['flash']) {
	Cookie('comview', '2');
} elseif ($_GET['comview']) {
	Cookie('comview', '1');
}

/* 判断该以什么方式浏览*/
if (isset($_GET['comview']) || (!isset($_GET['flash']) && GetCookie('comview') == 1)) {
	$flashView = 0; //已经进行了设置
} elseif (isset($_GET['flash']) || (!isset($_GET['comview']) && GetCookie('comview') == 2)) {
	$flashView = 1;
} else {
	$flashView = $very['flashview']; //默认方式
}
unset($_GET,$_POST,$_REQUEST);

Cookie('typeid', $typeid);
Cookie('page', $page);
if (empty($typeid))
{
	$typeid = 'all';
	$typename = '所有资源';
}
else
{
	$typename = $restype[$typeid]['typename']; ;
}
require_once(R_P . 'require/class_resource.php');
$res = new Resource();
//echo $typeid;

$res->setType($typeid);
$res->setWhere('delflag = 0');
$count = $res->getListNum();

//echo $count;

$pagesize = $typeid == 3 ? 24 : 30; //一页展示30个
if ($typeid == 2 || $typeid ==3)
{
	$flashView && $pagesize = 60; //flash浏览方式一次60个
}

$numofpage = ceil($count/$pagesize);
$pageurl = "type.php?typeid=$typeid&$urladd";
$orderBy = array(
	'cid' => '目录',
	'tid' => '所属' . $very['contentName'],
	'uploadtime' => '上传时间',
	'size' => '文件大小'
);
$orderString = array();
foreach ($orderBy as $key => $val)
{
	$orderString[] = "<a href=\"$pageurl&order=$key\">$val</a>";
}
$orderString = implode(" / ", $orderString);

if (isset($order))
{
	$pageurl .= "order=$order&";
	if (!array_key_exists($order, $orderBy))
	{
		$order = 'uploadtime';
	}
	$orderString = str_replace("$orderBy[$order]", "<span>$orderBy[$order]</span>", $orderString);
}
else 
{
	$orderString = str_replace($orderBy['uploadtime'], "<span>$orderBy[uploadtime]</span>", $orderString);
}

$resarray = $res->getList($page, $pagesize, $order);
$pages = numofpage($count, $page, $numofpage, "$pageurl");

start($very['charset']);
if ($typeid == 1)
{
	require $flashView ? Template('type-pic-flash') : Template('type-pic');
}
elseif ($typeid == 2)
{
	require Template('type-music');
}
elseif ($typeid == 3 && $very['convert'])
{
	require $flashView ? Template('type-pic-flash') : Template('type-video');
}
else
{
	require Template();
}
footer();
?>